
/****** Object:  StoredProcedure [usp_GetCRM_UsersByID]    Script Date: 3/17/2013 8:51:00 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[usp_GetCRM_UsersByID]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [usp_GetCRM_UsersByID];
GO

CREATE PROCEDURE [usp_GetCRM_UsersByID]
(
	@UserID int
)
AS
BEGIN
	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[UserID],
		[LoginID],
		[Password],
		[Role],
		[UserName],
		[Address],
		[MobileNo],
		[DOJ],
		[IsActive]
	FROM [CRM_Users]
	WHERE
		([UserID] = @UserID)

	SET @Err = @@Error

	RETURN @Err
END
GO


/****** Object:  StoredProcedure [usp_GetAllCRM_Users]    Script Date: 3/17/2013 8:51:01 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[usp_GetAllCRM_Users]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [usp_GetAllCRM_Users];
GO

CREATE PROCEDURE [usp_GetAllCRM_Users]
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[UserID],
		[LoginID],
		[Password],
		[Role],
		[UserName],
		[Address],
		[MobileNo],
		[DOJ],
		[IsActive]
	FROM [CRM_Users]

	SET @Err = @@Error

	RETURN @Err
END
GO


/****** Object:  StoredProcedure [usp_UpdateCRM_Users]    Script Date: 3/17/2013 8:51:01 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[usp_UpdateCRM_Users]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [usp_UpdateCRM_Users];
GO

CREATE PROCEDURE [usp_UpdateCRM_Users]
(
	@UserID int,
	@LoginID varchar(50),
	@Password nvarchar(50),
	@Role int,
	@UserName varchar(50),
	@Address varchar(MAX) = NULL,
	@MobileNo varchar(10),
	@DOJ datetime,
	@IsActive bit
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	UPDATE [CRM_Users]
	SET
		[LoginID] = @LoginID,
		[Password] = @Password,
		[Role] = @Role,
		[UserName] = @UserName,
		[Address] = @Address,
		[MobileNo] = @MobileNo,
		[DOJ] = @DOJ,
		[IsActive] = @IsActive
	WHERE
		[UserID] = @UserID


	SET @Err = @@Error


	RETURN @Err
END
GO




/****** Object:  StoredProcedure [usp_InsertCRM_Users]    Script Date: 3/17/2013 8:51:01 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[usp_InsertCRM_Users]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [usp_InsertCRM_Users];
GO

CREATE PROCEDURE [usp_InsertCRM_Users]
(
	@UserID int = NULL output,
	@LoginID varchar(50),
	@Password nvarchar(50),
	@Role int,
	@UserName varchar(50),
	@Address varchar(MAX) = NULL,
	@MobileNo varchar(10),
	@DOJ datetime,
	@IsActive bit
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	INSERT
	INTO [CRM_Users]
	(
		[LoginID],
		[Password],
		[Role],
		[UserName],
		[Address],
		[MobileNo],
		[DOJ],
		[IsActive]
	)
	VALUES
	(
		@LoginID,
		@Password,
		@Role,
		@UserName,
		@Address,
		@MobileNo,
		@DOJ,
		@IsActive
	)

	SET @Err = @@Error

	SELECT @UserID = SCOPE_IDENTITY()

	RETURN @Err
END
GO


/****** Object:  StoredProcedure [usp_DeleteCRM_Users]    Script Date: 3/17/2013 8:51:01 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[usp_DeleteCRM_Users]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [usp_DeleteCRM_Users];
GO

CREATE PROCEDURE [usp_DeleteCRM_Users]
(
	@UserID int
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	DELETE
	FROM [CRM_Users]
	WHERE
		[UserID] = @UserID
	SET @Err = @@Error

	RETURN @Err
END
GO

